<?php
App::uses('AppModel', 'Model');
App::uses('AuthComponent', 'Controller/Component');
/**
 * Usuario Model
 *
 * @property Perfil $Perfil
 * @property CitaHistorico $CitaHistorico
 * @property Cita $Cita
 * @property Fichero $Fichero
 * @property Lugar $Lugar
 * @property Observador $Observador
 */
class Usuario extends AppModel {

	/**
	 * Use database config
	 *
	 * @var string
	 */
	public $useDbConfig = 'default';

	/**
	 * Use table
	 *
	 * @var mixed False or table name
	 */
	public $useTable = 'usuario';
	
	/**
	 * Display field
	 *
	 * @var string
	 */
	public $displayField = 'username';


	//The Associations below have been created with all possible keys, those that are not needed can be removed

	/**
	 * belongsTo associations
	 *
	 * @var array
	 */
	public $belongsTo = array(
		'Perfil' => array(
			'className' => 'Perfil',
			'foreignKey' => 'perfil_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	/**
	 * hasMany associations
	 *
	 * @var array
	 */
	public $hasMany = array(
		'CitaHistorico' => array(
			'className' => 'CitaHistorico',
			'foreignKey' => 'usuario_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Cita' => array(
			'className' => 'Cita',
			'foreignKey' => 'usuario_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Fichero' => array(
			'className' => 'Fichero',
			'foreignKey' => 'usuario_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Lugar' => array(
			'className' => 'Lugar',
			'foreignKey' => 'usuario_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Observador' => array(
			'className' => 'Observador',
			'foreignKey' => 'usuario_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);

	/**
	 * Validaciones
	 */
	public $validate = array(
		'email' => array(
            'required' => array(
                'rule' => array('notEmpty'),
				'required' => true,
                'message' => 'El correo electrónico es obligatorio.'
            ),
            'email' => array(
		        'rule' => array('email', true),
		        'message' => 'Por favor indique un correo electrónico válido.'
		    ),
		    'maxLength' => array(
		        'rule' => array('maxLength', 128),
		        'message' => 'El tamaño máximo del correo electrónico son 128 caracteres.'
		    )
        ),
        'password' => array(
            'required' => array(
                'rule' => array('notEmpty'),
        		'required' => true,
                'message' => 'La contraseña es obligatoria.'
            ),
            'between' => array(
                'rule' => array('between', 8, 32),
                'message' => 'La contraseña debe contener un mímimo de 8 caracteres y un máximo de 32.'
            )
        )
	);
		
	/*public function beforeSave($options = array()) {
	    if (isset($this->data[$this->alias]['password'])) {
	        $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
	    }
	    return true;
	}*/
			
}
